package frobagroup.controller.frontEnd;

import frobagroup.services.frontEnd.CarouselFigureService;
import frobagroup.utils.Constants;
import frobagroup.utils.ResponseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by Tinsley on 2017/6/19.
 */
@RequestMapping("/webAPI/Carousel")
@RestController
public class CarouselFigureController {

    @Autowired
    private CarouselFigureService carouselFigureService;

    @RequestMapping(value = "/addOrEditCarousel", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> addOrEditCarousel(@RequestParam(value = "pic", required = false) MultipartFile pic,
                                                                   HttpServletRequest request,
                                                                   @RequestParam(value = "aId", required = false) String aId,
                                                                   @RequestParam(value = "cId", required = false) String cId,
                                                                   @RequestParam(value = "describe", required = false) String describe
    ) throws Exception{
        return ResponseModel.success(carouselFigureService.addOrEditCarousel(pic,(String)request.getAttribute("id"),aId,cId,describe),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/findCarousels", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> findCarousels(@RequestBody Map<String,String> params) throws Exception{
        return ResponseModel.success(carouselFigureService.findCarousels(params),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/changeStatus", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> changeStatus(@RequestParam(value = "cId", required = false) String cId,
                                                              @RequestParam(value = "status", required = false) String status,
                                                              HttpServletRequest request) throws Exception{
        return ResponseModel.success(carouselFigureService.changeStatus(cId,status,(String)request.getAttribute("id")),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/remove", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> remove(@RequestBody Map<String,String> params) throws Exception{
        carouselFigureService.remove(params.get("id"),params.get("picUrl"));
        return ResponseModel.success(null,
                Constants.RESPONSE_STATUS_SUCESS);
    }

}
